package cn.bugstack.test;

import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity;
import cn.bugstack.domain.strategy.repository.IStrategyRepository;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class Stream {

    @Resource
    private IStrategyRepository repository;
    @Test
    public void test1(){
        List<String> stringCollection = new ArrayList<>();
        stringCollection.add("ddd2");
        stringCollection.add("aaa2");
        stringCollection.add("bbb1");
        stringCollection.add("aaa1");
        stringCollection.add("bbb3");
        stringCollection.add("ccc");
        stringCollection.add("bbb2");
        stringCollection.add("ddd1");
        stringCollection.stream()
                .filter(s -> s.startsWith("a"))
                .forEach(System.out::println);

    }
    @Test
    public void test2(){
        List<StrategyAwardEntity> strategyAwardEntities= repository.queryStrategyAwardList(100001L);


       Optional<BigDecimal> max = strategyAwardEntities.stream().map(StrategyAwardEntity::getAwardRate).max(BigDecimal::compareTo);
        System.out.println(max);
//          获取最小概率值
//        BigDecimal minAwardRate = strategyAwardEntities.stream()
//                .map(StrategyAwardEntity::getAwardRate)
//                .min(BigDecimal::compareTo)
//                .orElse(BigDecimal.ZERO);

        List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
        String collect1 = names.stream().map(s -> s.charAt(0) + "").collect(Collectors.joining());
        List<Character> collect = names.stream().map(s -> s.charAt(0)).collect(Collectors.toList());
        System.out.println(collect);
    }

}
